package cn.kgc.maoqichao.microservicecloudconsumerdept80.controller;

import cn.kgc.maoqichao.microservicecloudproviderdept8001.pojo.Category;
import cn.kgc.maoqichao.microservicecloudproviderdept8001.pojo.ResultEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.List;
import java.util.Locale;

@RestController
@RequestMapping("/consumer/category")
public class CategoryController {
//    private static final String REST_URL_PREFIX="http://microservicecloud-provider-dept-8001/provider/category";

    private static final String REST_URL_PREFIX="http://MICROSERVICECLOUD-PROVIDER-DEPT";

    @Resource
    RestTemplate restTemplate;

    @RequestMapping("/list")
    public ResultEntity<List<Locale.Category>> list(){
        return restTemplate.getForObject(REST_URL_PREFIX+"/provider/category/list", ResultEntity.class);
    }

    @RequestMapping("/get/{id}")
    public ResultEntity<Locale.Category> get(@PathVariable Integer id){
        return restTemplate.getForObject(REST_URL_PREFIX+"/provider/category/get/"+id, ResultEntity.class);
    }

    @RequestMapping("/update")
    public ResultEntity<String> update(@RequestBody Locale.Category category){
        return restTemplate.postForObject(REST_URL_PREFIX+"/provider/category/update",category, ResultEntity.class);
    }

    @RequestMapping("/insert")
    public ResultEntity<String> insert(@RequestBody Category category){
        return restTemplate.postForObject(REST_URL_PREFIX+"/provider/category/insert",category, ResultEntity.class);
    }

    @RequestMapping("/delete/{id}")
    public ResultEntity<String> delete(@PathVariable Integer id){
        return restTemplate.getForObject(REST_URL_PREFIX+"/provider/category/delete/"+id, ResultEntity.class);
    }
}
